home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / e / amigae30a_fr.lha / AmigaE30f / Sources / Pd / FD2Module.e < prev    next >
Encoding:
Text File  |  1994-12-02  |  5.9 KB  |  206 lines

  1. /*
  2.  
  3. fd2module V1.0
  4. Alex McCracken Mar 1994
  5.  
  6. Ce programme est essentiellement basé sur Pragma2Module de Wouter van
  7. Oortmerssen. En fait, 90% de code appartient à Wouter, donc, pas de
  8. remerciement pour ça. Cependant, tant que le Pragma2Module de Wouter marche
  9. très bienpour les fichiers au bon format, je doit admettre que si ça plante,
  10. c'est certainement de ma faute. Vous pouvez utiliser ce programme si il vous
  11. convient. S'il doit planter et mange votre chien, fait exploser votre TV, ou
  12. cause des problêmes quelconques, on ne pourra pas me rendre responsable. En
  13. d'autres mots, utilisez le à vos propres risques. J'ai fait tous les efforts
  14. pour m'assurer qu'il marche, mais je ne peut garantir d'avoir trouvé tous les
  15. petits trucs qui plante tous les programmes.
  16.  
  17. Utilisation
  18.  
  19. Le programme est appelé en tapant (CLI uniquement):
  20.  
  21.         fd2module <libname>
  22.  
  23. où libname est le nom du fichier sans _lib.fd.
  24. Ca produira un fichier <libname>.m. Pour le moment le programme annonce que le
  25. fichier fd est lu, mais ca peut changer dans le futur. Vous devez donner
  26. au programme le nom de la bibliothèque explicitement (mais, encore une fois,
  27. ça peut changer.
  28.  
  29. Distribution
  30.  
  31. Ceci peut être distribué par n'importe quel moyen. Cependant, je retient le
  32. droit de mettre à niveau l'ensemble sans informer quiconque. Cette distribution
  33. contient :
  34.         fd2module               L'éxécutable
  35.         fd2module.doc           Ce document
  36.  
  37. Me contacter
  38.  
  39. Je peut être joind :
  40.  
  41. par courier postal:
  42.         Alex McCracken
  43.         11 Charles Street
  44.         Kilmarnock
  45.         Ayrshire
  46.         KA1 2DX
  47.         Scotland
  48.  
  49. par courier Internet :
  50.         mccracal@dcs.gla.ac.uk
  51.  
  52. Je n'utilise mon compte email que pendant les temps 'Term', donc pendant l'été
  53. il vaudrait mieux m'envoyer un lettre par la poste. L'adresse email devrait rester
  54. valide jusqu'à l'été 95.
  55.  
  56. */
  57.  
  58. /* FD2Module
  59.    convertis un fichier bibliothèque fd en un module E.
  60.    Usage: fd2module <file>
  61.    convertis <file_lib.fd> en <file.m>                  */
  62.  
  63. ENUM INPUT_ERROR=10,OUTPUT_ERROR,FORMAT_ERROR
  64.  
  65. DEF cfh,efh,eof,done,
  66.     gotbase=FALSE,
  67.     public=TRUE,
  68.     offset=30,
  69.     cfile[200]:STRING,
  70.     efile[200]:STRING,
  71.     cstring[200]:STRING
  72.  
  73. PROC main()
  74.   StrCopy(cfile,arg,ALL)
  75.   StrAdd(cfile,'_lib.fd',ALL)
  76.   StrCopy(efile,arg,ALL)
  77.   StrAdd(efile,'.m',ALL)
  78.   WriteF('Amiga E FD2Module\nconvertis: "\s" en "\s"\n',cfile,efile)
  79.   IF (cfh:=Open(cfile,OLDFILE))=0 THEN closeall(INPUT_ERROR)
  80.   IF (efh:=Open(efile,NEWFILE))=0 THEN closeall(OUTPUT_ERROR)
  81.   REPEAT
  82.     eof:=ReadStr(cfh,cstring)
  83.     done:=convert(cstring)
  84.   UNTIL eof OR done
  85.   WriteF('dernier offset: -\d\n',offset)
  86.   Out(efh,$FF)
  87.   WriteF('Terminé.\n')
  88.   closeall(0)
  89. ENDPROC
  90.  
  91. PROC closeall(er)
  92.   IF cfh<>0 THEN Close(cfh)
  93.   IF efh<>0 THEN Close(efh)
  94.   SELECT er
  95.     CASE INPUT_ERROR;  WriteF('Ne peut pas ouvrir le fichier d\aentrée!\n')
  96.     CASE OUTPUT_ERROR; WriteF('Ne peut pas ouvrir le fichier de sortie!\n')
  97.     CASE FORMAT_ERROR; WriteF('Erreur dans le format du fichier définition des fonctions!\n')
  98.   ENDSELECT
  99.   CleanUp(er)
  100. ENDPROC
  101.  
  102. /* format de ligne à convertir:
  103.    ##base _<Basename>
  104.      or
  105.    ##bias <offset>
  106.      or
  107.    ##public
  108.      or
  109.    ##private
  110.      or
  111.    ##end
  112.      or
  113.    * <comment>
  114.      or
  115.    <funcname>(<paramlist>)(<reglist>)*/
  116.  
  117. PROC convert(str)
  118. DEF     pos,pos2,off2,len,narg,a,empty,dstr[50]:STRING,basestr[50]:STRING,
  119.         funcstr[50]:STRING,regstr[20]:STRING,libstr[50]:STRING,
  120.         tstr[80]:STRING,t2str[80]:STRING,t3str[80]:STRING,reg,check
  121.   MidStr(tstr,str,TrimStr(str)-str,ALL)
  122.   LowerStr(tstr)
  123.   WriteF('\s\n',str)
  124.   IF StrCmp(tstr,'##base ',STRLEN) OR StrCmp(tstr,'##base\t',STRLEN)
  125.     pos:=STRLEN
  126.     pos2:=InStr(tstr,'_',0)
  127.     IF pos2=-1 THEN closeall(FORMAT_ERROR)
  128.     IF gotbase=FALSE
  129.       gotbase:=TRUE
  130.       MidStr(basestr,str,(pos2+1),ALL)
  131.       LowerStr(basestr)
  132.       WriteF('Base will be: \s\n',basestr)
  133.       WriteF('Correct name of this library (with the ".library" or ".device"):\n>')
  134.       ReadStr(stdout,libstr)
  135.       Write(efh,["EM","OD",6]:INT,6)
  136.       Write(efh,libstr,EstrLen(libstr)+1)
  137.       Write(efh,basestr,EstrLen(basestr)+1)
  138.     ENDIF
  139.   ELSEIF StrCmp(tstr,'##bias ',STRLEN) OR StrCmp(tstr,'##bias\t',STRLEN)
  140.     pos:=STRLEN
  141.     MidStr(t2str,tstr,pos,ALL)
  142.     pos2:=TrimStr(t2str)
  143.     MidStr(t3str,t2str,pos2-t2str,ALL)
  144.     off2:=Val(t3str,NIL)
  145.     IF off2=0 THEN closeall(FORMAT_ERROR)
  146.     WHILE off2<>offset
  147.       Write(efh,'Dum',3)                     /* "Emplacement vide de fonction" */
  148.       Out(efh,16)
  149.       IF offset>off2 THEN closeall(FORMAT_ERROR)
  150.       offset:=offset+6
  151.     ENDWHILE
  152.   ELSEIF StrCmp(tstr,'##private',ALL)
  153.     public:=FALSE
  154.   ELSEIF StrCmp(tstr,'##public',ALL)
  155.     public:=TRUE
  156.   ELSEIF StrCmp(tstr,'##end',ALL)
  157.     RETURN TRUE
  158.   ELSEIF StrCmp(tstr,'*',STRLEN)
  159.     NOP
  160.   ELSE
  161.     IF public
  162.       pos:=0
  163.       pos2:=InStr(str,'(',pos)
  164.       IF pos2=-1 THEN closeall(FORMAT_ERROR)
  165.       MidStr(funcstr,str,pos,pos2-pos)
  166.       IF funcstr[0]>="a" THEN funcstr[0]:=funcstr[0]-32
  167.       IF funcstr[1]<"a" THEN funcstr[1]:=funcstr[1]+32
  168.       Write(efh,funcstr,EstrLen(funcstr))
  169.       pos:=pos2+1
  170.       pos2:=InStr(str,'(',pos)
  171.       IF pos2=-1 THEN closeall(FORMAT_ERROR)
  172.       narg:=0
  173.       MidStr(dstr,str,pos2+1,ALL)
  174.       UpperStr(dstr)
  175.       WHILE StrCmp(dstr,')',1)=FALSE
  176.         IF EstrLen(dstr)<2 THEN closeall(FORMAT_ERROR)
  177.         MidStr(regstr,dstr,0,2)
  178.         IF StrCmp(regstr,'D',1) OR StrCmp(regstr,'A',1)
  179.           IF StrCmp(regstr,'D',1)
  180.             reg:=0
  181.           ELSEIF StrCmp(regstr,'A',1)
  182.             reg:=8
  183.           ENDIF
  184.           MidStr(regstr,regstr,1,ALL)
  185.           reg:=reg+Val(regstr,{check})
  186.           IF check<1 THEN closeall(FORMAT_ERROR)
  187.         ELSE
  188.           closeall(FORMAT_ERROR)
  189.         ENDIF
  190.         MidStr(dstr,dstr,2,ALL)
  191.         IF StrCmp(dstr,',',1) OR StrCmp(dstr,'/',1)
  192.           MidStr(dstr,dstr,1,ALL)
  193.         ENDIF
  194.         Out(efh,reg)
  195.         INC narg
  196.       ENDWHILE
  197.       IF narg=0 THEN Out(efh,16)
  198.       offset:=offset+6
  199.     ELSE
  200.       Write(efh,'Dum',3)
  201.       Out(efh,16)
  202.       offset:=offset+6
  203.     ENDIF
  204.   ENDIF
  205. ENDPROC FALSE
  206.